package org.lex.elec.model.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

import org.apache.commons.dbutils.handlers.AbstractListHandler;
import org.apache.commons.lang3.StringUtils;
import org.lex.elec.model.domain.Cable;

public class CableResultSetHandler extends AbstractListHandler<Cable> {
	private final static String ID = "id";
	private final static String MODEL = "model";
	private final static String NAME = "name";
	private final static String WORKING_TEMPERATURE = "working_temperature";
	private final static String ATLAS = "atlas";
	private final static String DESCRIPTION = "description";
	private final static String TECH_CREATEDATE = "tech_createdate";

	@Override
	protected Cable handleRow(ResultSet rs) throws SQLException {
		Cable o = new Cable();
		// id
		o.setId(rs.getInt(ID));
		// model
		o.setModel(StringUtils.trim(rs.getString(MODEL)));
		// name
		o.setName(StringUtils.trim(rs.getString(NAME)));
		// working temperature
		o.setWorkingTemperature(rs.getInt(WORKING_TEMPERATURE));
		// atlas
		o.setAtlasId(rs.getInt(ATLAS));
		// description
		o.setDescription(StringUtils.trim(rs.getString(DESCRIPTION)));
		// techCreate
		java.sql.Timestamp createDate = rs.getTimestamp(TECH_CREATEDATE);
		if (null != createDate) {
			o.setTechCreateDate(new Date(createDate.getTime()));
		}
		return o;
	}

}
